package net.sea.setup.ui.wizard.impl;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.util.List;

import javax.swing.JCheckBox;
import javax.swing.JLabel;

import net.sea.commons.constants.AppConstants;
import net.sea.commons.context.AppContext;
import net.sea.commons.util.ShellUtils;
import net.sea.setup.config.custom.CustomConfig;
import net.sea.setup.ui.wizard.AbstractWizardPage;

/**
 * 安装完成页面
 * 
 * @author 华成伍
 *
 */
@SuppressWarnings("serial")
public class CompletePage extends AbstractWizardPage {
	// 运行平台的复选框
	JCheckBox runCheckBox = new JCheckBox(
			"\u8FD0\u884C\u6613\u5F00\u5E73\u53F0");
	// readme文件打开的复选框
	JCheckBox reademeCheckBox = new JCheckBox("\u67E5\u770Breadme\u6587\u4EF6");

	public CompletePage() {
		setBorder("\u7A0B\u5E8F\u5B89\u88C5\u5B8C\u6210");
		GridBagLayout gridBagLayout = new GridBagLayout();
		gridBagLayout.columnWidths = new int[] { 10, 100, 350, 0, 0 };
		gridBagLayout.rowHeights = new int[] { 100, 0, 150, 0, 0, 0, 0 };
		gridBagLayout.columnWeights = new double[] { 0.0, 0.0, 0.0, 0.0,
				Double.MIN_VALUE };
		gridBagLayout.rowWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
				Double.MIN_VALUE };
		setLayout(gridBagLayout);

		JLabel tipLb = new JLabel(
				"<html>\u606D\u559C\u60A8\uFF01<br>\u6613\u6D4B\u5E73\u53F0\u5B89\u88C5\u6210\u529F\u3002<html>");
		GridBagConstraints gbc_tipLb = new GridBagConstraints();
		gbc_tipLb.gridwidth = 2;
		gbc_tipLb.insets = new Insets(0, 0, 5, 5);
		gbc_tipLb.gridx = 1;
		gbc_tipLb.gridy = 1;
		add(tipLb, gbc_tipLb);

//		GridBagConstraints gbc_runCheckBox = new GridBagConstraints();
//		gbc_runCheckBox.anchor = GridBagConstraints.WEST;
//		gbc_runCheckBox.insets = new Insets(0, 0, 5, 5);
//		gbc_runCheckBox.gridx = 2;
//		gbc_runCheckBox.gridy = 3;
//		add(runCheckBox, gbc_runCheckBox);

		GridBagConstraints gbc_reademeCheckBox = new GridBagConstraints();
		gbc_reademeCheckBox.anchor = GridBagConstraints.WEST;
		gbc_reademeCheckBox.insets = new Insets(0, 0, 5, 5);
		gbc_reademeCheckBox.gridx = 2;
		gbc_reademeCheckBox.gridy = 4;
		add(reademeCheckBox, gbc_reademeCheckBox);
	}

	@Override
	public PageResult validateInput() {
		return new PageResult(true);
	}

	@Override
	protected List<CustomConfig> createCustomConfig() {
		return null;
	}

	@Override
	public void done() {
		super.done();
		new Thread(new Runnable() {
			
			@Override
			public void run() {
				String installDir = (String) AppContext.getInstance().getAttribute(
						"INSTALL_DIR");
				if (runCheckBox.isSelected()) {
					ShellUtils.callCmd(installDir + "/ide/eclipse/eclipse.exe");
				}
				if (reademeCheckBox.isSelected()) {
					ShellUtils.callCmd(installDir + "/readme.txt");
				}
			}
		}).start();
	}

	@Override
	public void process() {
		super.process();
		contextInst.setAttribute(AppConstants.ROLLBACK_FLAG, false);
	}

}
